﻿using Abp.Application.Services.Dto;
using Abp.AspNetCore.Mvc.Controllers;
using Abp.Runtime.Validation;
using Batman.Cms.Controllers.Weixins.Input;
using Batman.Cms.Services.Weixins;
using Microsoft.AspNetCore.Mvc;

namespace Batman.Cms.Controllers.Weixins
{
    public class WeixinMpAccountController : AbpController
    {
        public WeixinMpAccountAppSvc WeixinMpAccountAppSvc { get; set; }

        public ActionResult Index(PagedResultRequestDto page, WeixinMpAccountFilter filter)
        {
            var model = WeixinMpAccountAppSvc.GetWeixinMpAccounts(page, filter);
            return View(model);
        }

        public ActionResult GetWeixinMpAccounts(PagedResultRequestDto page, WeixinMpAccountFilter filter)
        {
            var model = WeixinMpAccountAppSvc.GetWeixinMpAccounts(page, filter);
            return Json(model);
        }

        public ActionResult Create()
        {
            return View(new CreateWeixinMpAccountInput());
        }


        [DisableValidation]
        [HttpPost]
        public ActionResult Create(CreateWeixinMpAccountInput model)
        {
            var result = WeixinMpAccountAppSvc.Create(model);
            if (!result.Success)
            {
                result.AddModelError(ModelState);
                return View(model);
            }

            return Content("创建成功");
        }

        public ActionResult Update(int id)
        {
            var model = WeixinMpAccountAppSvc.Get<UpdateWeixinMpAccountInput>(id);
            return View(model);
        }


        [DisableValidation]
        [HttpPost]
        public ActionResult Update(UpdateWeixinMpAccountInput model)
        {
            var result = WeixinMpAccountAppSvc.Update(model);
            if (!result.Success)
            {
                result.AddModelError(ModelState);
                return View(model);
            }

            return Content("编辑成功");
        }

    }
}
